home *** CD-ROM | disk | FTP | other *** search
/ Magnum One / Magnum One (Mid-American Digital) (Disc Manufacturing).iso / d12 / cchh01.arc / JCWFUNC.H < prev    next >
Text File  |  1986-03-14  |  22KB  |  307 lines

  1. /*------------------------------------------------------------------*/
  2. /* JCWFUNC.H -- This is a set of C library routines created by      */
  3. /*              Weilandt Software International, a subsidiary       */
  4. /*              of Weilandt Industries Incorporated.                */
  5. /*                                                                  */
  6. /* POINT    -- select cursor row and column using ASCII values      */
  7. /* CLEAR    -- clear the screen                                     */
  8. /* SCREEN   -- select screen attributes                             */
  9. /* EEOL     -- erase to end of line                                 */
  10. /* ITOA     -- convert an integer to an ASCII string                */
  11. /* POSITION -- locate the row and column of the cursor              */
  12. /* POINTI   -- select cursor row and column using integer values    */
  13. /* COLOR    -- select screen foreground and background colors       */
  14. /* EEOS     -- erase to end of screen from cursor position          */
  15. /* EHTC     -- erase from home position to cursor position          */
  16. /* CTRANS   -- pseudo translate and test function for strings       */
  17. /*                                                                  */
  18. /*------------------------------------------------------------------*/
  19. /*------------------------------------------------------------------*/
  20. /*  POINT -- function to move the cursor around the screen using    */
  21. /*           extended screen management (ANSI.SYS).                 */
  22. /*                                                                  */
  23. /*  arguments:                                                      */
  24. /*      row    -- pointer to a string variable which contains the   */
  25. /*                row number to move the cursor to.                 */
  26. /*      column -- pointer to a string variable which contains the   */
  27. /*                column number to move the curser to.              */
  28. /*                                                                  */
  29. /*  example:                                                        */
  30. /*      point("5","20"); -- moves the cursor to row 5 column 20.    */
  31. /*                                                                  */
  32. /*  author: J.C. Weilandt II  date: 11-29-84  updated: 11-30-84     */
  33. /*------------------------------------------------------------------*/
  34. point( row, column)                    /* Define point screen func  */
  35.     char *row, *column;                /* Define string pointers    */
  36.   {                                    /* Open the function         */
  37.     static char csbuf[80] = "\x1B[";   /* Define point buffer       */
  38.     int ret_code;                      /* define local variable     */
  39.     strcat(csbuf,row);                 /* add the row number        */
  40.     strcat(csbuf,";");                 /* add a semi-colon          */
  41.     strcat(csbuf,column);              /* add the column number     */
  42.     strcat(csbuf,"f");                 /* add ANSI function byte    */
  43.     ret_code = write(1,&csbuf,strlen(csbuf)); /* issue point string */
  44.     strcpy(csbuf,"\x1B[");             /* reset initial buffer      */
  45.   }                                    /* Terminate C Function      */
  46. /*------------------------------------------------------------------*/
  47. /*  CLEAR -- function to clear the screen of the IBM PC using       */
  48. /*           extended screen management (ANSI.SYS).                 */
  49. /*                                                                  */
  50. /*  arguments:                                                      */
  51. /*      none                                                        */
  52. /*                                                                  */
  53. /*  example:                                                        */
  54. /*      clear();         -- clears the screen                       */
  55. /*                                                                  */
  56. /*  author: J.C. Weilandt II  date: 11-29-84  updated: 11-30-84     */
  57. /*------------------------------------------------------------------*/
  58. clear()                                /* Define clear screen func  */
  59.   {                                    /* Open the function         */
  60.     int ret_code;                      /* define local variable     */
  61.     ret_code = write(1,"\x1B[2J",4);   /* clear the screen          */
  62.   }                                    /* Terminate C Function      */
  63. /*------------------------------------------------------------------*/
  64. /*  SCREEN   -- function to change attributes of the PC screen      */
  65. /*              analagous to the 3270 SF attributes.                */
  66. /*                                                                  */
  67. /*  arguments:                                                      */
  68. /*      attr -- where attr is a string variable containing:         */
  69. /*              "HIGH"      -- High Intensity                       */
  70. /*              "LOW"       -- Low Intensity                        */
  71. /*              "NORMAL"    -- Low Intensity                        */
  72. /*              "REVERSE"   -- Reverse Video                        */
  73. /*              "BLINK"     -- Blinking                             */
  74. /*              "INVISIBLE" -- Next field not displayed             */
  75. /*                                                                  */
  76. /*  example:                                                        */
  77. /*      screen("HIGH");  -- sets high intensity mode                */
  78. /*                                                                  */
  79. /*  author: J.C. Weilandt II  date: 12-01-84  updated: 12-06-84     */
  80. /*------------------------------------------------------------------*/
  81. screen(attr)                           /* Define screen function    */
  82.   char *attr;                          /* Attr is a string pointer  */
  83.   {                                    /* Open the function         */
  84.     int ret_code;                      /* define local variable     */
  85.     int max = 1;                       /* define compare length     */
  86.     if (strncmp(attr,"H",max) == 0)    /* q. selected high ??       */
  87.       ret_code = write(1,"\x1B[1m",4); /*    yes, issue high seq    */
  88.     else if (strncmp(attr,"L",max) == 0) /*  selected low ??        */
  89.       ret_code = write(1,"\x1B[0m",4); /*    yes, issue low seq     */
  90.     else if (strncmp(attr,"N",max) == 0) /*  selected low ??        */
  91.       ret_code = write(1,"\x1B[0m",4); /*    yes, issue low seq     */
  92.     else if (strncmp(attr,"R",max) == 0) /*  selected reverse ??    */
  93.       ret_code = write(1,"\x1B[7m",4); /*    yes, issue reverse seq */
  94.     else if (strncmp(attr,"B",max) == 0) /*  selected blink ??      */
  95.       ret_code = write(1,"\x1B[5m",4); /*    yes, issue blink seq   */
  96.     else if (strncmp(attr,"I",max) == 0) /*  selected invisible ?   */
  97.       ret_code = write(1,"\x1B[8m",4); /*    yes, issue blink seq   */
  98.     else puts("Invalid Screen Attribute"); /* error message         */
  99.   }                                    /* Terminate C Function      */
  100. /*------------------------------------------------------------------*/
  101. /*  EEOL  -- function to clear from the cursor to the end of the    */
  102. /*           current line, extended screen management (ANSI.SYS).   */
  103. /*                                                                  */
  104. /*  arguments:                                                      */
  105. /*      none                                                        */
  106. /*                                                                  */
  107. /*  example:                                                        */
  108. /*      eeol();          -- erase from the cursor to end of line    */
  109. /*                                                                  */
  110. /*  author: J.C. Weilandt II  date: 12-01-84  updated: 12-01-84     */
  111. /*------------------------------------------------------------------*/
  112. eeol()                                 /* Define eeol screen func   */
  113.   {                                    /* Open the function         */
  114.     int ret_code;                      /* define local variable     */
  115.     ret_code = write(1,"\x1B[K",3);    /* erase to end of line      */
  116.   }                                    /* Terminate C Function      */
  117. /*------------------------------------------------------------------*/
  118. /*  ITOA  -- function to create an ASCII string (maximum length     */
  119. /*           of 10 bytes) from an integer value.                    */
  120. /*                                                                  */
  121. /*  arguments:                                                      */
  122. /*      buf -- pointer to the character string in which to store    */
  123. /*             the ASCII output.                                    */
  124. /*      num -- integer value to be converted.                       */
  125. /*                                                                  */
  126. /*  example:                                                        */
  127. /*      itoa(buffer,5)   -- make digit 5 an ASCII string.           */
  128. /*                                                                  */
  129. /*  author: J.C. Weilandt II  date: 12-05-84  updated: 12-05-84     */
  130. /*------------------------------------------------------------------*/
  131. itoa(buf, num)                         /* define ITOA function      */
  132.   char *buf;                           /* declare buffer pointer    */
  133.   int num;                             /* declare int to convert    */
  134.   {                                    /* open the function         */
  135.     int local;                         /* declare dummy variable    */
  136.     local = stcu_d(buf, num, 9);       /* invoke system function    */
  137.   }                                    /* terminate ITOA function   */
  138. /*------------------------------------------------------------------*/
  139. /*  POSITION -- function to return the row and column position      */
  140. /*              of the cursor.                                      */
  141. /*                                                                  */
  142. /*  arguments:                                                      */
  143. /*      row -- integer to receive the current cursor row.           */
  144. /*      col -- integer to receive the current cursor column.        */
  145. /*                                                                  */
  146. /*  example:                                                        */
  147. /*      position(&row,&col) -- return the row and column values.    */
  148. /*                                                                  */
  149. /*  author: J.C. Weilandt II  date: 12-06-84  updated: 12-06-84     */
  150. /*------------------------------------------------------------------*/
  151. position(row,col)                  /* declare function header       */
  152.   int *row, *col;                  /* define pointers to integers   */
  153.   {                                /* open function procedure       */
  154.     char *r, *c;                   /* define work pointers          */
  155.     pcvgcp(r,c);                   /* acquire row and column BIOS   */
  156.     *row = *r + 1;                 /* return row to integer         */
  157.     *col = *c + 1;                 /* return column to integer      */
  158.   }                                /* terminate position function   */
  159. /*------------------------------------------------------------------*/
  160. /*  POINTI -- function to move the cursor around the screen using   */
  161. /*            extended screen management (ANSI.SYS).                */
  162. /*                                                                  */
  163. /*  arguments:                                                      */
  164. /*      row    -- integer variable containing the row number to     */
  165. /*                move the cursor to.                               */
  166. /*      column -- integer variable containing the column number to  */
  167. /*                move the cursor to.                               */
  168. /*                                                                  */
  169. /*  example:                                                        */
  170. /*      pointi(5,20);    -- moves the cursor to row 5 column 20.    */
  171. /*                                                                  */
  172. /*  author: J.C. Weilandt II  date: 12-06-84  updated: 12-06-84     */
  173. /*------------------------------------------------------------------*/
  174. pointi(row,col)                    /* define pointi function        */
  175.   int row, col;                    /* declare function arguments    */
  176.   {                                /* open the function structure   */
  177.     char r_buf[10];                /* define ASCII string holder    */
  178.     char c_buf[10];                /* define ASCII string holder    */
  179.     itoa(r_buf,row);               /* translate row to ASCII        */
  180.     itoa(c_buf,col);               /* translate column to ASCII     */
  181.     point(r_buf,c_buf);            /* issue normal point function   */
  182.   }                                /* close the pointi function     */
  183. /*------------------------------------------------------------------*/
  184. /*  COLOR    -- function to change the foreground and               */
  185. /*              background colors of the PC screen.                 */
  186. /*                                                                  */
  187. /*  arguments:                                                      */
  188. /*      fore -- foreground color string                             */
  189. /*      back -- background color string                             */
  190. /*                                                                  */
  191. /*  colors: BLACK, RED, GREEN, YELLOW, BLUE,                        */
  192. /*          MAGENTA, CYAN, WHITE                                    */
  193. /*                                                                  */
  194. /*  example:                                                        */
  195. /*      color("YELLOW","BLUE"); -- yellow on blue background        */
  196. /*                                                                  */
  197. /*  author: J.C. Weilandt II  date: 12-06-84  updated: 12-07-84     */
  198. /*------------------------------------------------------------------*/
  199. color(col_1,col_2)                     /* Define color function     */
  200.   char *col_1, *col_2;                 /* Declare string pointers   */
  201.   {                                    /* Open the function         */
  202.     int i;                             /* define loop tester        */
  203.     int ret_code;                      /* define local variable     */
  204.     static char *colors[8] = {         /* define color list         */
  205.       "BLACK","RED","GREEN","YELLOW",  /*   colors                  */
  206.       "BLUE","MAGENTA","CYAN","WHITE" }; /*  more colors            */
  207.     static char *colorl[8] = {         /* define color list         */
  208.       "black","red","green","yellow",  /*   colors                  */
  209.       "blue","magenta","cyan","white" }; /*  more colors            */
  210.     static char *fore[8] = {           /* define foreground equivs  */
  211.       "30","31","32","33","34","35","36","37"}; /* equivalents      */
  212.     static char *back[8] = {           /* define background equivs  */
  213.       "40","41","42","43","44","45","46","47"}; /* equivalents      */
  214.     static char csbuf[80] = "\x1B[";   /* Define color buffer       */
  215.     for (i=0; i<8; i++)                /* Define procedure loop     */
  216.       {                                /* open inner procedure      */
  217.         if ((strncmp(colors[i],col_1,3) == 0) || /* do we have      */
  218.             (strncmp(colorl[i],col_1,3) == 0))   /*    a match ??   */
  219.           {                            /* yes, open inner-inner pr  */
  220.             strcat(csbuf,fore[i]);     /* load equivalent           */
  221.             break;                     /* terminate the for loop    */
  222.           }                            /* terminate inner-inner pr  */
  223.       }                                /* close inner procedure     */
  224.     strcat(csbuf,";");                 /* add a semi-colon          */
  225.     for (i=0; i<8; i++)                /* Define procedure loop     */
  226.       {                                /* open inner procedure      */
  227.         if ((strncmp(colors[i],col_2,3) == 0) || /* do we have      */
  228.             (strncmp(colorl[i],col_2,3) == 0))   /*    a match ??   */
  229.           {                            /* yes, open inner-inner pr  */
  230.             strcat(csbuf,back[i]);     /* load equivalent           */
  231.             break;                     /* terminate the for loop    */
  232.           }                            /* terminate inner-inner pr  */
  233.       }                                /* close inner procedure     */
  234.     strcat(csbuf,"m");                 /* add ANSI function byte    */
  235.     ret_code = write(1,&csbuf,strlen(csbuf)); /* issue color string */
  236.     strcpy(csbuf,"\x1B[");             /* reset initial buffer      */
  237.   }                                    /* terminate color function  */
  238. /*------------------------------------------------------------------*/
  239. /*  EEOS  -- function to clear from the cursor to the end of the    */
  240. /*           current screen, extended screen management (ANSI.SYS). */
  241. /*                                                                  */
  242. /*  arguments:                                                      */
  243. /*      none                                                        */
  244. /*                                                                  */
  245. /*  example:                                                        */
  246. /*      eeos();          -- erase from the cursor to end of screen  */
  247. /*                                                                  */
  248. /*  author: J.C. Weilandt II  date: 12-23-84  updated: 12-23-84     */
  249. /*------------------------------------------------------------------*/
  250. eeos()                                 /* Define eeos screen func   */
  251.   {                                    /* Open the function         */
  252.     int ret_code;                      /* define local variable     */
  253.     ret_code = write(1,"\x1B[0J",4);   /* erase to end of screen    */
  254.   }                                    /* Terminate C Function      */
  255. /*------------------------------------------------------------------*/
  256. /*  EHTC  -- function to clear from the home position to the        */
  257. /*           cursor position, extended screen management (ANSI.SYS).*/
  258. /*                                                                  */
  259. /*  arguments:                                                      */
  260. /*      none                                                        */
  261. /*                                                                  */
  262. /*  example:                                                        */
  263. /*      ehtc();          -- erase from home to cursor position      */
  264. /*                                                                  */
  265. /*  author: J.C. Weilandt II  date: 12-23-84  updated: 12-23-84     */
  266. /*------------------------------------------------------------------*/
  267. ehtc()                                 /* Define ehtc screen func   */
  268.   {                                    /* Open the function         */
  269.     int ret_code;                      /* define local variable     */
  270.     ret_code = write(1,"\x1B[1J",4);   /* erase to cursor from home */
  271.   }                                    /* Terminate C Function      */
  272. /*------------------------------------------------------------------*/
  273. /*  CTRANS -- function to scan a string and replace every           */
  274. /*            occurance of one character with another.              */
  275. /*                                                                  */
  276. /*  arguments:                                                      */
  277. /*      string -- character string containing chars to be replaced  */
  278. /*      old    -- character variable for character to be replaced   */
  279. /*      new    -- character variable holding replacement character  */
  280. /*                                                                  */
  281. /*  example:                                                        */
  282. /*      ctrans(string,'_',' '); replace every underscore character  */
  283. /*                              with a blank.                       */
  284. /*                                                                  */
  285. /*  author: J.C. Weilandt II  date: 02-10-85  updated: 02-10-85     */
  286. /*------------------------------------------------------------------*/
  287. ctrans(c_str,old,new)                  /* Define function and parms */
  288.   char *c_str;                         /* Passed input string       */
  289.   char old, new;                       /* passed character vars     */
  290.   {                                    /* open C function proper    */
  291.     char *strchr();                    /* define called function    */
  292.     int r_offset;                      /* define string offset      */
  293.     char *offset;                      /* define actual offset      */
  294.     int x_test = 0;                    /* define loop controller    */
  295.     while (x_test == 0)                /* do until all converted    */
  296.       {                                /* open while loop           */
  297.         offset = strchr(c_str,old);    /* point to char for replace */
  298.         if (offset == 0)               /* Q. are we all done ??     */
  299.           {                            /*    yes, open procedure    */
  300.             x_test = 1;                /*    set finished indicator */
  301.             break;                     /*    get out of while       */
  302.           }                            /*    terminate procedure    */
  303.         r_offset = offset - c_str;     /* point to addr of char     */
  304.         c_str[r_offset] = new;         /* replace with new char     */
  305.       }                                /* terminate while loop      */
  306.   }                                    /* terminate C function      */
  307.